<?php 
    require 'comm/chkLoginState.php';
    require 'comm/header.php';
    require 'comm/page.php';
    $index = new DB();
    $page = 1;
    if($_GET){ $page = $_GET['page']; }
    $pages = new page($page,'admin_info');
    //查询
    if($_POST){
        $name = $_POST['name'];
        $pwd = $_POST['pwd'];
        $arr = array();
        $where = '';
        //用户有可能查询几个方式
        if(!empty($name) && empty($pwd)){ 
            $where .= " where admin_name like '%".$name."%'";
        }else if(!empty($pwd) && empty($name)){  
            $where .= " where admin_pwd like '%".$pwd."%'";
        }else if(!empty($name) && !empty($pwd)){
            $where .=" where admin_name like '%".$name."%' and admin_pwd like '%".$pwd."%'";
        }
        $arr = $pages->pages($where);
        $pagecount = $pages->pagecount;  //页数
    }else{ //没有查询 显示所有
        $arr = $pages->pages();
        $pagecount = $pages->pagecount;
    }     
       
        //$arr = $index->select('admin_info');
    
    
?>
<div class="card">
             <div class="card-header">
                    <strong>查询</strong>
             </div>
            <div class="card-block">
                 <form action="admin_index.php" method="post" class="form-inline">
                      <div class="form-group">
                         <label for="exampleInputName2">用户名</label>
                         <input type="text" class="form-control" id="exampleInputName2" placeholder="Jane Doe" name = 'name'>
                       </div>
                      <div class="form-group">密码</label>
                          <input type="text" class="form-control" id="exampleInputEmail2" placeholder="password" name ='pwd'>
                      </div>
                          <input type="submit" class="btn btn-sm btn-primary" value = '查询'>
                  </form>
            </div>
</div>
        <div class="card">
                          <div class="card-header">
                                    <i class="fa fa-align-justify"></i>用户信息
                                </div>
                                <a class="page-link" href="admin_insert.php" style='width:100px;'>新增</a>
                                <div class="card-block">
                                    <table class="table">
                                        <thead>
                                            <tr>
                                                <th>编号</th>
                                                <th>用户名</th>
                                                <th>密码</th>
                                                <th>操作</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        <?php foreach ($arr as $k=>$v){ ?>
                                            <tr>
                                                <td><?php echo $v['admin_id'];?></td>
                                                <td><?php echo $v['admin_name'];?></td>
                                                <td><?php echo $v['admin_pwd'];?></td>
                                                <td>
                                                    <a class="nav-link nav-dropdown-toggle" style='width:100px;float:left;' href="admin_update.php?id=<?php echo $v['admin_id'];?>">修改</a>
                                                    <a class="nav-link nav-dropdown-toggle" onclick="return confirm('确定要删除?')" href="admin_del.php?id=<?php echo $v['admin_id'];?>" style='width:100px;float:left;'>删除</a>
                                                </td>
                                            </tr>
                                          <?php }?>
                                        </tbody>
                                    </table>
                                    <ul class="pagination">
                                        <li class="page-item"><a class="page-link" href="#">Prev</a>
                                        </li>
                                        <li class="page-item active">
                                            <a class="page-link" href="admin_index.php?page=1">1</a>
                                        </li>
                                        <?php for ($i=2;$i<=$pagecount;$i++){?>
                                        <li class="page-item"><a class="page-link" href="admin_index.php?page=<?php echo $i?>"><?php echo $i;?></a></li>
                                        <?php }?>
                                        <li class="page-item"><a class="page-link" href="admin_index.php?page=<?php echo $page?>">Next</a>
                                        </li>
                                    </ul>
                                </div>
                                <?php require 'comm/footer.php';?>